#include "Log.h"

bool logging::Log::_initialised;
logging::Log logging::Log::_instance;

logging::Log::Log(void)
{
	_initialised = true;
}

logging::Log::~Log(void)
{
	_initialised = false;
}

logging::Log* logging::Log::getInstance(void)
{
	return _initialised ? &_instance : 0;
}

void logging::Log::info(string msg)
{
	cout << getCurrentTime() << " INFO: " << msg << endl;
}

void logging::Log::warning(string msg)
{
	cout << getCurrentTime() << " WARNING: " << msg << endl;
}

void logging::Log::error(string msg)
{
	cout << getCurrentTime() << " ERROR: " << msg << endl;
}

void logging::Log::message(string level, string msg)
{
	cout << getCurrentTime() << " " << level << ": " << msg << endl;
}

string logging::Log::getCurrentTime(void)
{
	time_t currentUnformattedTime;
	time(&currentUnformattedTime);
	struct tm* currentGMTTime = gmtime(&currentUnformattedTime);
	string formattedTime = "";
	stringstream ss;
	ss << currentGMTTime->tm_hour;
	formattedTime.append(ss.str()).append(":");
	ss.str("");
	ss << currentGMTTime->tm_min;
	formattedTime.append(ss.str()).append(":");
	ss.str("");
	ss << currentGMTTime->tm_sec;
	formattedTime.append(ss.str());
	
	return formattedTime;
}
